const Config = require('./confing.js')

function netWork(obj) {
     //obj.para处理加密

     // if (obj.auth){
     // }
     console.log("正在请求" + Config.BaseUrl + obj.url)
     // console.log(obj.para)
     // console.log(new Date())
     wx.request({
          url: Config.BaseUrl + obj.url,//请求地址，string
          data: obj.para || {},//请求参数obj
          header: {
               "content-type": obj.contentType || obj.method == 'POST' ? 'application/x-www-form-urlencoded' : 'application/json',
               'token': wx.getStorageSync("token")
          },//请求头
          method: obj.method || 'GET',//请求方式
          // contentType,
          //     isPermissions = false,//是否认证
          dataType: 'json',
          responseType: 'text',
          success: function (res) {
               if (typeof obj.success === "function") {
                    obj.success(res)
               }
               
          },
          fail: function (err) {
               wx.showToast({
                    title: "您的网络不给力",
                    icon: "none",
                    duration: 2000
               })
               if (typeof obj.fail === "function") {
                    obj.fail(err)
               }
          },
          complete: function (res) {
               if (typeof obj.complete === "function") {
                    obj.complete(res)
               }

          }
     })
}
// function xx(){
// console.log("我是xxx")
// }

module.exports = {
     netWork
}